package com.mars.basic.service;

import com.mars.basic.allmain.po.AdminUser;
import com.mars.basic.allmain.po.Article;
import com.mars.basic.allmain.vo.article.ArticleVo;
import com.mars.basic.repo.ArticleRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * @author Marvrick
 */
@Service
public class ArticleService {

    @Autowired
    private ArticleRepository articleRepository;

    public ArticleRepository getArticleRepository() {
        return articleRepository;
    }

    public void addArticle(ArticleVo vo, AdminUser user) {
        Article article = vo.build();
        article.setCreateTime(new Date());
        article.setUserId(user.getId());
        article.setAuthor(user.getName());
        getArticleRepository().save(article);
    }
}
